log4net 记录wpf 错误日志
using System;using System.Collections.Generic;using System.Configuration;using System.Data;using System.Linq;using System.Windows;using Common;namespace WpfApplication1{ /// <summary> /// App.xaml 的交互逻辑 /// </summary> public partial class App : Application { public App() { this.DispatcherUnhandledException = new System.Windows.Threading.DispatcherUnhandledExceptionEventHandler(App_DispatcherUnhandledException); AppDomain.CurrentDomain.UnhandledException = new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); } void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) { if (e.ExceptionObject is System.Exception) { LogHelper.ErrorLog(null, (System.Exception)e.ExceptionObject); } } public static void HandleException(Exception ex) { LogHelper.ErrorLog(null,ex); } void App_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e) { e.Handled = true; LogHelper.ErrorLog(null, e.Exception); } }}
评论